<!doctype html>
<html>
<head>
	<meta charset="utf-8">
    <title>评论图片审核</title>
    <link href="nprogress.css" rel="stylesheet" />
    <style>
        *{margin:0;padding:0;}
        /*top menu class*/
        .menu{
            width:100%;
            line-height:90px;
            -webkit-box-shadow:0 0 15px #bbb!important;
            -moz-box-shadow:0 0 15px #bbb!important;
            box-shadow:0 0 15px #bbb!important;
            margin-bottom: 15px;
            text-align: center;
        }
        input[type=text], input[type=password] {
            font-size: 13px;
            min-height: 32px;
            margin: 0;
            padding: 7px 8px;
            outline: none;
            color: #333;
            background-color: #fff;
            background-repeat: no-repeat;
            background-position: right center;
            border: 1px solid #d2d2d2;
            border-radius: 3px;
            box-shadow: inset 0 1px 2px rgba(0,0,0,0.075);
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            transition: all 0.15s ease-in;
            -webkit-transition: all 0.15s ease-in 0;
            vertical-align: middle;
        }
        #search input[type=text] {
            font-size: 18px;
            width: 500px;
        }
        .button {
            position: relative;
            display: inline-block;
            margin: 0;
            padding: 8px 15px;
            font-size: 13px;
            color: #555;
            font-weight: bold;
            white-space: nowrap;
            background-color: #eaeaea;
            background-image: -moz-linear-gradient(#fafafa, #eaeaea);
            background-image: -webkit-linear-gradient(#fafafa, #eaeaea);
            background-image: linear-gradient(#fafafa, #eaeaea);
            background-repeat: repeat-x;
            border-radius: 3px;
            border: 1px solid #ddd;
            border-bottom-color: #c5c5c5;
            box-shadow: 0 1px 3px rgba(0,0,0,.05);
            vertical-align: middle;
            cursor: pointer;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            -khtml-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            -webkit-appearance: none;
        }
        #search .button {
            padding: 10px;
            width: 90px;
        }
        .del-btn{
            background-image: -moz-linear-gradient(#d9534f, #d43f3a);
            background-image: -webkit-linear-gradient(#d9534f, #d43f3a);
            background-image: linear-gradient(#d9534f, #d43f3a);
            color:#fff;
            border-bottom-color:#ccc;
        }
        .pass-btn{
            background-image: -moz-linear-gradient(#5cb85c, #4cae4c);
            background-image: -webkit-linear-gradient(#5cb85c, #4cae4c);
            background-image: linear-gradient(#5cb85c, #4cae4c);
            color:#fff;
            border-bottom-color:#ccc;
        }
        /*img container class*/
        .row{
            width:98%;
            margin: 0 auto;
        }
        .row > .img-block{
            float:left;
            width:10%;
            margin: 0 auto 15px auto;
        }
        .row > .img-block > .thumbnail{
            padding:10px 0;
            width:92%;
            height:230px;
            text-align:center;
            -webkit-box-shadow:0 0 10px #ddd;
            -moz-box-shadow:0 0 10px #ddd;
            box-shadow:0 0 10px #ddd;
            border:1px solid #fff;
            border-top-width: 2px;
            border-bottom-width: 2px;
        }
        .row > .img-block > .thumbnail > img{
            max-width:100%;
            max-height:200px;
            margin:0 auto;
            border-radius: 8px;
        }
        .img-hover > .thumbnail{
            -webkit-box-shadow:0 0 10px #7a0!important;
            -moz-box-shadow:0 0 10px #7a0!important;
            box-shadow:0 0 10px #7a0!important;
        }
        .img-checked{
            border-color:mediumvioletred!important;
        }
        .ml100{margin-left:100px;}
    </style>
</head>
<body>
    <div class="menu">
        <div id="search">
        <input type="text" id="key" placeholder="输入名称搜索">
        <input class="button" type="button" id="btn-search" value="搜索">
        <input class="button ml100 pass-btn" type="button" id="btn-pass" value="审核">
        <input class="button del-btn" type="button" id="btn-delete" value="删除">
    </div>
    </div>

    <div class="row" id="container"></div>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="nprogress.js"></script>
<script>
    var cn = 'img-block';
    var ic = 'img-checked';
    var imgManger = {

        render: function(data){
            var html = '';
            for (var i=0; i<data.length; i++){
                html += '<div class="img-block">'+
                        '    <div class="thumbnail" dataid="'+data[i].id+'">'+
                        '        <img src="'+data[i].img+'" alt="...">'+
                        '        <div class="caption">'+
                        '            <h4>'+data[i].name+'</h4>'+
                        '        </div>'+
                        '    </div>'+
                        '</div>';
            };
            document.getElementById("container").innerHTML = html;
        },

        getImgs: function(){
            var ids = [];
            var ckd = document.getElementsByClassName(ic);
            for (var i=0; i<ckd.length; i++){
                ids.push(ckd[i].attributes.dataid.value);
            };
            return ids;
        },

        init: function(){
            var self = this;
            var imgObjs = document.getElementsByClassName(cn);
            for (var i = 0; i < imgObjs.length; i++) {
                imgObjs[i].onclick = self.imgClick;
                imgObjs[i].onmouseenter = self.imgHover;
                imgObjs[i].onmouseleave = self.imgOut;
            };
        },

        imgClick: function(){
            var tb = this.getElementsByClassName('thumbnail')[0];

            if (tb.className.indexOf(ic) == -1){
                tb.className += ' '+ic;
            }else{
                var classes = tb.className.split(' ');
                for (var i=0; i<classes.length; i++){
                    if (classes[i]==ic){
                        delete classes[i];
                    };
                };
                tb.className = classes.join(' ');
            };
        },

        imgHover: function(){
            var ih = 'img-hover';
            if (this.className.indexOf(ih) == -1){
                this.className += ' '+ih;
            };
        },

        imgOut: function(){
            var ih = 'img-hover';
            if (this.className.indexOf(ih) > -1){
                this.className = cn;
            };
        }

    };
    
    dd = [
        {
            'img':'https://image7.benlailife.com/ProductImages/000/000/013/256/big/d0e76253-47ff-43f8-84f7-8b65a23b5f4e.jpg',
            'name':'新疆库尔勒',
            'id':10
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image7.benlailife.com/ProductImages/000/000/013/256/big/d0e76253-47ff-43f8-84f7-8b65a23b5f4e.jpg',
            'name':'新疆库尔勒',
            'id':10
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },{
            'img':'https://image7.benlailife.com/ProductImages/000/000/013/256/big/d0e76253-47ff-43f8-84f7-8b65a23b5f4e.jpg',
            'name':'新疆库尔勒',
            'id':10
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        },
        {
            'img':'https://image6.benlailife.com/OnlineHomePageImage/0/3/8ef54565-6cbe-41a1-ad70-8134464f59d4.jpg?imageView2/2/format/webp',
            'name':'哈萨克斯坦',
            'id':11
        }
    ]
    $(function(){
        var imgM = imgManger;
        //imgM.init()
        $('#btn-pass,#btn-delete').click(function(){
            var actionType = this.id.replace("btn-","");
            var ids = imgM.getImgs();
            if (ids.length==0){
                alert('请至少选择一个项目！');
                return false;
            };
            NProgress.start();
            $.ajax({
                type: "POST",
                url: "post.json",
                data: { ids:ids, type:actionType },
                dataType: "json",
                success: function(msg){
                    alert(msg);
                },
                complete: function(){
                    NProgress.done();
                }
            });
        });

        $('#btn-search').click(function(){
            var key = $("#key").val();
            if (key==''){
                alert("请输入查询内容！");
                return false;
            };
            NProgress.start();
            $.ajax({
                type: "GET",
                url: "/search.json",
                data: { key:key },
                dataType: "json",
                success: function(data){
                    imgM.render(data);
                    imgM.init();
                },
                complete: function(){
                    imgM.render(dd);
                    imgM.init();
                    NProgress.done();
                }
            });
        });
    });
</script>
</body>
</html>